home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Support / BCExcept.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  3.5 KB  |  145 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  Restricted Rights Legend
  5. //  Use, duplication, or disclosure is subject to restrictions as set forth 
  6. //  in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer 
  7. //  Software clause at DFARS 252.227-7013. 
  8. //
  9. //  BCExcept.cpp
  10. //
  11. //  This file contains the definitions for the classes and functions
  12. //  associated with exception handling.
  13.  
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "BCExcept.h"
  17.  
  18. #ifdef BC_CAN_EXPORT_DATA
  19. const char* BC_SHARED_DATA BC_kDisjoint = "objects are members of different structures";
  20. const char* BC_SHARED_DATA BC_kDuplicate = "object already exists";
  21. const char* BC_SHARED_DATA BC_kEmpty = "object is empty";
  22. const char* BC_SHARED_DATA BC_kFull = "object is full";
  23. const char* BC_SHARED_DATA BC_kIllegal = "illegal pattern";
  24. const char* BC_SHARED_DATA BC_kInvalidIndex = "index is out of range";
  25. const char* BC_SHARED_DATA BC_kInvalidNumber = "string does not denote a valid number";
  26. const char* BC_SHARED_DATA BC_kMissing = "object does not exist";
  27. const char* BC_SHARED_DATA BC_kNull = "object is null";
  28. const char* BC_SHARED_DATA BC_kNotEmpty = "object is not empty";
  29. const char* BC_SHARED_DATA BC_kNotRoot = "object is not at root of structure";
  30. const char* BC_SHARED_DATA BC_kOutOfMemory = "free storage exhausted";
  31. const char* BC_SHARED_DATA BC_kReferenced = "object is referenced and cannot be destroyed";
  32. const char* BC_SHARED_DATA BC_kTooLarge = "object is too large";
  33. const char* BC_SHARED_DATA BC_kTooSmall = "object is too small";
  34. #else
  35. const char* BC_Get_kDisjoint()
  36. {
  37.     return "objects are members of different structures";
  38. }
  39.  
  40. const char* BC_Get_kDuplicate()
  41. {
  42.     return "object already exists";
  43. }
  44.  
  45. const char* BC_Get_kEmpty()
  46. {
  47.     return "object is empty";
  48. }
  49.  
  50. const char* BC_Get_kFull()
  51. {
  52.     return "object is full";
  53. }
  54.  
  55. const char* BC_Get_kIllegal()
  56. {
  57.     return "illegal pattern";
  58. }
  59.  
  60. const char* BC_Get_kInvalidIndex()
  61. {
  62.     return "index is out of range";
  63. }
  64.  
  65. const char* BC_Get_kInvalidNumber()
  66. {
  67.     return "string does not denote a valid number";
  68. }
  69.  
  70. const char* BC_Get_kMissing()
  71. {
  72.     return "object does not exist";
  73. }
  74.  
  75. const char* BC_Get_kNotEmpty()
  76. {
  77.     return "object is not empty";
  78. }
  79.  
  80. const char* BC_Get_kNotRoot()
  81. {
  82.     return "object is not at root of structure";
  83. }
  84.  
  85. const char* BC_Get_kNull()
  86. {
  87.     return "object is null";
  88. }
  89.  
  90. const char* BC_Get_kOutOfMemory()
  91. {
  92.     return "object is null";
  93. }
  94.  
  95. const char* BC_Get_kReferenced()
  96. {
  97.     return "object is referenced and cannot be destroyed";
  98. }
  99.  
  100. const char* BC_Get_kTooLarge()
  101. {
  102.     return "object is too large";
  103. }
  104.  
  105. const char* BC_Get_kTooSmall()
  106. {
  107.     return "object is too small";
  108. }
  109.  
  110. #endif
  111.  
  112. BC_XException::BC_XException(const char* name, const char* who, const char* what)
  113. {
  114.   fName[0] = fWho[0] = fWhat[0] = '\0';
  115. #ifdef BC_DEBUG
  116.   if (name)
  117.     strncpy(fName, name, BC_MAXIMUM_LENGTH);
  118.   if (who)
  119.     strncpy(fWho,  who , BC_MAXIMUM_LENGTH);
  120.   if (what)
  121.     strncpy(fWhat, what, BC_MAXIMUM_LENGTH);
  122.   fName[BC_MAXIMUM_LENGTH] = fWho [BC_MAXIMUM_LENGTH] = fWhat[BC_MAXIMUM_LENGTH] = '\0';
  123. #endif
  124. }
  125.  
  126. void BC_XException::Display() const
  127. {
  128. #ifdef FW_DEBUG
  129.     FW_CDebugConsole* debugConsole = FW_CDebugConsole::GetConsole();
  130.     FW_CDebugStream& debugStream = debugConsole->GetFatalErrorStream();
  131.   debugStream << fName << " (who: " << fWho << ", what: " << fWhat << ")";
  132. #endif
  133. }
  134.  
  135. void BC_Catch(const BC_XException& e)
  136. {
  137. #ifdef FW_DEBUG
  138.     FW_CDebugConsole* debugConsole = FW_CDebugConsole::GetConsole();
  139.     FW_CDebugStream& debugStream = debugConsole->GetFatalErrorStream();
  140.   debugStream << "EXCEPTION: ";
  141. #endif
  142.   e.Display();
  143.   exit(1);
  144. }
  145.